package study.saas.web.portal.sys.admin;

import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import study.saas.common.viewmodel.ApiResultV2;
import study.saas.order.entity.Commodity;
import study.saas.order.service.CommodityFacade;
import study.saas.order.service.model.*;

@Api(tags = "商品管理")
@RestController
@RequestMapping(value = "sys/commodity")
public class CommodityController {
    @Reference(version = "1.0.0")
    private CommodityFacade commodityFacade;

    @ApiOperation(value = "获取")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public ApiResultV2<Commodity> get(Integer commodityId) {
        if (commodityId == null ) {
            return ApiResultV2.error("数据不能为空！");
        }

        return commodityFacade.get(commodityId);
    }

    @ApiOperation(value = "创建")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public ApiResultV2 create(CommodityCreateDTO create) {
        if (create == null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return commodityFacade.create(create);
    }

    @ApiOperation(value = "修改")
    @RequestMapping(value = "/decrease", method = RequestMethod.POST)
    public ApiResultV2 decrease(CommodityDecreaseDTO decrease) {
        if (decrease == null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return commodityFacade.decrease(decrease);
    }
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ApiResultV2 delete(Integer commodityId) {
        if (commodityId == null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return commodityFacade.delete(commodityId);
    }
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResultV2 list(CommodityFilterDTO filter) {
        if (filter == null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return commodityFacade.list(filter);
    }


}
